const Client = require('node-rest-client').Client;
// auth
const Options_auth = { user: "xx", password: "xx" };
var client = new Client(Options_auth);


// 查询某个issue信息
// client.get('http://jira.in.zhihu.com/rest/api/2/issue/QA-630', function(data, response) {
//     // console.log(response);
//     console.log(data);
// })


// 添加Project 版本号 如： http://jira.in.zhihu.com/rest/api/2/project/QA/versions 或 http://jira.in.zhihu.com/rest/api/2/project/QA/version
// 添加版本号必填字段：1. 版本号name 2.项目project对应的Id
// 参考API：https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-version-post
const projectKey = 'QA';
const postURL = 'http://jira.in.zhihu.com/rest/api/2/project/' + projectKey + '/version';
const args = {
    data: {
        "description": '自动插入的版本号, @' + new Date(),
        "name": "1.1.0(76)",
        "projectId": 10119
    },
    headers: { "Content-Type": "application/json" }
};
client.post('http://jira.in.zhihu.com/rest/api/2/version', args, function(data, response) {
    console.log(data);
    // console.log(response);
});

// 删除某个项目的版本号
// 删除某个版本号 只需提供版本号对应的id即可.(不再需要项目id)
// 参考API：https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-version-id-delete
// client.delete('http://jira.in.zhihu.com/rest/api/2/version' + '/' + '12727', function(data, response) {
//     console.log(data);
//     // console.log(response);
// });




// 查询
// var searchArgs = {
//     headers: {
//         // Set the cookie from the session information
//         'Accept': 'application/json',
//         "Content-Type": "application/json"
//     },
//     data: {
//         // Provide additional data for the Jira search. You can modify the JQL to search for whatever you want.
//         jql: "type=Bug AND status=Closed"
//     }
// };
// client.post("http://jira.in.zhihu.com/rest/api/2/search", searchArgs, function(searchResult, response) {
//     console.log('status code:', response.statusCode);
//     console.log('search result:', searchResult);
// });